package com.rules.admin.controller.decision;

import com.rules.admin.entity.TreeNode;
import com.rules.admin.service.TreeNodeService;
import com.rules.admin.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping({"/decisionTreeNodes"})
public class DecisionTreeNodeController {
   @Autowired
   private TreeNodeService treeNodeService;

   @RequestMapping(
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public Map<String, Object> saveTreeNode(@RequestBody TreeNode treeNode) {
      this.treeNodeService.create(treeNode);
      return ResultUtils.getSuccessResultData(treeNode);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.PUT}
   )
   @ResponseBody
   public Map<String, Object> updateTreeNode(@RequestBody TreeNode treeNode) {
      this.treeNodeService.updateById(treeNode);
      return ResultUtils.getSuccessResultData(treeNode);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.DELETE}
   )
   @ResponseBody
   public Map<String, Object> deleteTreeNode(@PathVariable Long id) {
      this.treeNodeService.removeById(id);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getTreeNode(@PathVariable long id) {
      TreeNode treeNode = (TreeNode)this.treeNodeService.getById(id);
      return ResultUtils.getSuccessResultData(treeNode);
   }
}
